package com.amigo.online.message.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.amigo.online.common.core.response.Result;
import com.amigo.online.message.enums.MIMCUrlEnum;
;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * 会话列表
 */

@Api( "最近会话列表")
@RestController
@RequestMapping("/sessionList")
public class SessionListController {

    @ApiOperation(value = "获取最近会话列表版本二" ,  notes="获取最近会话列表版本二")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token"),
    })
    @PostMapping("/getSessionList")
    public Result getSessionList(String token){
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type","application/json");
        headers.add("token", token);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("msgExtraFlag",true);
        HttpEntity<JSONObject> requestEntity = new HttpEntity<JSONObject>(jsonObject, headers);
        ResponseEntity<JSONObject> responseEntity = restTemplate.exchange(MIMCUrlEnum.SESSION_LIST.getValue()+"?msgExtraFlag=true", HttpMethod.GET , requestEntity , JSONObject.class);
        JSONObject responseJson = responseEntity.getBody();
        System.out.println(responseJson.getInteger("code"));
        if(responseJson.getInteger("code")==200){
            JSONArray array = responseJson.getJSONObject("data").getJSONArray("contacts");
            return Result.success(array);
        }else {
            return Result.error();
        }

    }
    public static void main(String[] args) {
//        SessionListController controller =new SessionListController();
//        String token = "bJRLeg7AgtSh0T13YjL/IH3t2iak8hsS1prkxsxcrwbAbtDwd2ctZdx4KNb8cfAqAzyOPgJKDn3lgRkqPcJ7FZfls3/Girj3lslYZbEsORAJS/zfHt7g8ahBDlLNNEePz23NCfV1GzuAhyP8f92R8PF0lYdBgbKUMIp3z9oclOuRfvZOiHYWIRvX0URaGxUFDXT1knNCmZOjFRBFVOzQvLPsp369EJGa6cLy4fwmJwRgcMky3pGxW3CBAUk/BbjpuzmGjwklPWtPZeljfx6WrYz2pi+yiSzGG+HcVy6B3107PvxwKFYUZw/c1NSBvO4sDekBseutoTgVzlLsUsvckuURwdKVDezP0EZVT4lN/Mv/tlM2QEhkSEidFsnFYyHJSul1QWl4BmqX58bn6xwlAvAx54ILlTlrrDw1n8cSgzaCnYzZ1m15esvoMatC2OxhjexowtN4lo4ego1bgPYpEw==";
//        System.out.println(controller.getSessionList(token));

    }
}
